<?php

// Avoid unstubbing $wgParser on setHook() too early on modern (1.12+) MW 
// versions, as per r35980
if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) )
{
	$wgHooks['ParserFirstCallInit'][] = 'efTexifyInit';
}
else
{ 
	// Otherwise do things the old fashioned way
	$wgExtensionFunctions[] = 'efTexifyInit';
}
 
function efTexifyInit()
{
	global $wgParser;
	$wgParser->setHook( 'texify', 'efTexifyHook' );
	return true;
}
 
function efTexifyHook( $input, $args, $parser )
{
	// $attr = array();
	$size = "";
	$fullURL = "";
	$fullTag = "";
	
	// This time, make a list of attributes and their values,
	// and dump them, along with the user input
	foreach( $args as $name => $value )
	{
		/* $attr[] = '<strong>' . htmlspecialchars( $name ) .
		'</strong> = ' . htmlspecialchars( $value ); */
		if ( htmlspecialchars( $name ) == 'size' )
		{
			switch ( strtolower ( htmlspecialchars ( $value ) ) )
			{
				case 'normal':
					$size = htmlspecialchars ( $value );
					break;
				case 'large':
					$size = htmlspecialchars ( $value );
					break;
				case 'huge':
					$size = htmlspecialchars ( $value );
					break;
				default:
					$size = htmlspecialchars ( "normalsize" );
			}
		}
	}
	$fullURL = "http://www.texify.com/img/" . urlencode ( "\\" . $size . "\\" . 
		htmlspecialchars( trim( $input ) ) ) . ".gif";
	$fullTag = "<img src=\"$fullURL\" />";
	return  ( $fullTag );
}

?>